package com.zq.behavior.duty_chain;

import java.util.stream.IntStream;

public class Client {

    public static void main(String[] args) {
        int[] ints = IntStream.rangeClosed(0, 10).toArray();

        OnlyOnceHandler.Builder<Integer> builder = new OnlyOnceHandler.Builder<>();
        OnlyOnceHandler<Integer> onceHandler = builder.add(i -> i % 2 == 0, i -> {
            System.out.println(i + "是偶数");
        }).add(i -> i < 5, i -> {
            System.out.println(i + "小于5");
        }).build();

        AllHandler.Builder<Integer> builder1 = new AllHandler.Builder<>();
        AllHandler<Integer> allHandler = builder1.add(i -> i % 2 == 0, i -> {
            System.out.println(i + "是偶数");
        }).add(i -> i < 5, i -> {
            System.out.println(i + "小于5");
        }).build();

        for (int i : ints) {
            onceHandler.handle(i);
        }

        System.out.println("--------------------------------");

        for (int i : ints) {
            allHandler.handle(i);
        }
    }
}
